package com.sa.token.controller;

import com.sa.token.dto.request.user.LoginRequest;
import com.sa.token.message.StandardResponse;
import com.sa.token.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @desc： 登录注册
 * @author： xhs
 * @date： 2021/8/19 12:54
 * @version： JDK 1.8
 */
@Slf4j
@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    /**
     * 注册
     *
     * @param loginRequest
     * @return
     */
    @PostMapping("/register")
    public StandardResponse<Object> register(@Valid @RequestBody LoginRequest loginRequest) {
        return loginService.register(loginRequest);
    }

    /**
     * 登录
     *
     * @param loginRequest
     * @return
     */
    @PostMapping("/login")
    public StandardResponse<Object> login(@Valid @RequestBody LoginRequest loginRequest, HttpServletRequest request) {
        return loginService.login(request,loginRequest);
    }

    /**
     * 登出
     *
     * @return
     */
    @PostMapping("/logout")
    public StandardResponse<Object> logout() {
        return loginService.logout();
    }
}
